package mspbots.cw.business.core.timeentry;

import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Mono;

/**
 * @author Jay.Yang
 */
public interface TimeEntriesRepository extends R2dbcRepository<TimeEntry, Long> {

    /**
     * find entity other id and tenant id
     *
     * @param timeentry  timeentry
     * @param tenantCode tenantCode
     * @return account entity
     */
    Mono<TimeEntry> findByTimeentryIdAndTenantCode(Long timeentry, Long tenantCode);

    /**
     * count time entry
     *
     * @param tenantCode tenant
     * @param ticketId   ticket
     * @param flag       falg
     * @return count result
     */
    @Query("select count(*) from task_cw_timeentry where tenant_code=:tenantCode and ticket_id=:ticketId and add_to_resolution_flag=:flag")
    Mono<Integer> countTimeEntryBy(Long tenantCode, Long ticketId, Boolean flag);

}
